﻿﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace QuanLyQuangCao
{
    public class Myconection
    {
        //public string sqlconn = "server=lydv-hp\\mydata;database=quangcao;uid=sa;pwd=123456";
        public SqlConnection con = new SqlConnection(@"Data Source=thonglh;Initial Catalog=QuanLyQuangCao;Integrated Security=True");
        
        public void GetData(string sql, string sqlconn, DataSet ds, string datatablename)
        {
            SqlConnection sc = new SqlConnection(sqlconn);
            sc.Open();

            SqlCommand scmd = new SqlCommand(sql, sc);

            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = scmd;

            if ((ds != null) && (ds.Tables.Contains(datatablename)))
            {
                ds.Tables[datatablename].Clear();
                sda.Fill(ds, datatablename);
                sc.Close();
            }
        }
    }
}
